
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();//获取项目名称
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";//完整的项目路径
%>
<base href="<%=basePath%>">
<html>
<head>
    <title>Title</title>
    <script src="static/js/jQuery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            button()
            $("#btn").click(function () {
                $("#tbody").html("");
                button()
        })})




        function button() {

                $.ajax({
                    url:"http://localhost:8080/Springmvc_SSM1/Student/query",
                    method:"post",
                    dataType:"json",
                    success:function (res) {
                        var string ="";
                        for (let i=0;i<res.length;i++){
                          string= string+"<tr><td>" +res[i].name+"</td><td>"+res[i].age+"</td></tr>"
                        }
                        $("#tbody").html(string);
                    }})}

    </script>
</head>
<body>
<div align="center">
    <table>
        <tr><td>
            姓名
        </td>
            <td>
                年龄
            </td></tr>
        <tbody id="tbody">

        </tbody>
        <input type="button" id="btn" value="查询学生"></input></td>

    </table>
</div>
</body>
</html>
